cc.Class({
    extends: cc.Component,

    properties: {
        
    },

    onLoad: function () {
        //屏蔽底部点击事件
        cc.find('mask', this.node).on(cc.Node.EventType.TOUCH_START, function (event) {});
        
        var howtoplay_node = cc.find("dikuang", this.node);
        howtoplay_node.setPosition(cc.p(-2000, 0));
        howtoplay_node.runAction(cc.moveTo(0.2, cc.p(0, 0)));
        
        var self = this;
        var caozuo_node = cc.find("dikuang/neirong_caozuo", this.node);
        var paixing_node = cc.find("dikuang/neirong_paixing", this.node);
        caozuo_node.active = false;
        paixing_node.active = false;
        for (let i = 0; i < 3; i++) {
            var toggle_node = cc.find("dikuang/toggleGroup/toggle" + i, this.node);
            toggle_node.on(cc.Node.EventType.TOUCH_END, function (event) {
                self.onToggle(i);
            });
        }
    },
    
    //点击按钮
    onToggle: function (index) {
        var wanfa_node = cc.find("dikuang/neirong_wanfa", this.node);
        var caozuo_node = cc.find("dikuang/neirong_caozuo", this.node);
        var paixing_node = cc.find("dikuang/neirong_paixing", this.node);
        switch (index) {
            case 0:
                wanfa_node.active = true;
                caozuo_node.active = false;
                paixing_node.active = false;
                break;
            case 1:
                wanfa_node.active = false;
                caozuo_node.active = false;
                paixing_node.active = true;
                break;
            case 2:
                wanfa_node.active = false;
                caozuo_node.active = true;
                paixing_node.active = false;
                break;
        }
    },

    onClose: function () {
        var howtoplay_node = cc.find("dikuang", this.node);
        howtoplay_node.runAction(cc.sequence(
            cc.moveTo(0.5, cc.p(2000, 0)),
            cc.callFunc(this.exitThisNode, this)
            ));
    },
    
    //删除当前节点
    exitThisNode: function () {
        this.node.destroy();
    },
});
